﻿//-----------------------------------------------------------------------------------------//
//-     Writen by Raymond Honderdors
//-     2013-05-14
//-
//-     Code can be used as is, no warrenty
//-     https://solutionmanagementki.codeplex.com/
//-----------------------------------------------------------------------------------------//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AnalysisServices;

namespace SMK_SSAS
{
    /// <summary>
    /// 
    /// </summary>
    public class AMO_Database_Dimension
    {
        private Microsoft.AnalysisServices.Dimension amodimension = null;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Datebase"></param>
        /// <param name="CubeID"></param>
        public void SetAMODatabaseCube(AMO_Database Datebase, string CubeID)
        {

            if (Datebase != null)
            {
                AMO_Server Server = Datebase.AMOServer();
                if (Server.Isconnected())
                {
                    if (Datebase.amodatabase().Dimensions.Contains(CubeID))
                    {
                        amodimension = Datebase.amodatabase().Dimensions.Find(CubeID);
                    }
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasAttributes()
        {
            if (amodimension != null)
            {
                if (amodimension.Attributes.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasDimensionPermissions()
        {
            if (amodimension != null)
            {
                if (amodimension.DimensionPermissions.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasHierarchies()
        {
            if (amodimension != null)
            {
                if (amodimension.Hierarchies.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasRelationships()
        {
            if (amodimension != null)
            {
                if (amodimension.Relationships.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean HasTranslations()
        {
            if (amodimension != null)
            {
                if (amodimension.Translations.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> DatabaseDimensionAttributes()
        {
            if (amodimension != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Dimension db in amodimension.Attributes)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amodimension.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> DatabaseDimensionPermissions()
        {
            if (amodimension != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Dimension db in amodimension.DimensionPermissions)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amodimension.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> DatabaseDimensionHierarchies()
        {
            if (amodimension != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Dimension db in amodimension.Hierarchies)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amodimension.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> DatabaseDimensionRelationships()
        {
            if (amodimension != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Dimension db in amodimension.Relationships)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amodimension.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SortedList<string, AMO_Key> DatabaseDimensionTranslations()
        {
            if (amodimension != null)
            {
                SortedList<string, AMO_Key> result = new SortedList<string, AMO_Key>();
                foreach (Microsoft.AnalysisServices.Dimension db in amodimension.Translations)
                {
                    AMO_Key amok = new AMO_Key();
                    amok.ID = db.ID;
                    amok.Name = db.Name;
                    result.Add(amodimension.Name + "\\" + db.ID, amok);
                }
                return result;
            }
            else
            {
                return null;
            }
        }
    }
}
